/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package studenttrack.entity;

import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.util.ArrayList;
import stException.LecturerAlreadyAssociatedWithModuleException;
import stException.LecturerNotAssociatedWithModuleException;
import stException.ModuleAlreadyOnCourseException;
import stException.ModuleNotOnCourseException;
import stException.PreReqModuleAlreadyAssociatedWithModuleException;
import stException.PreReqModuleNotAssociatedWithModuleException;
import stException.StudentAlreadyOnCourseException;
import stException.StudentNotOnCourseException;

/**
 *
 * @author tg227
 */
@Entity
public class ModuleI implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private String id;

    public String getCode() {
        return id;
    }

    public void setCode(String code) {
        this.id = code;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ModuleI)) {
            return false;
        }
        ModuleI other = (ModuleI) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "studenttrack.entity.Course[id=" + id + "]";
    }

    //end gen code

    private String name;
    private int creditWeighting;
    private char stage;
    private ArrayList<String> preReqModuleList;
    private ArrayList<String> studentList;
    private String coordinatorID;
    private ArrayList<String> lecturers;

    public int getCreditWeighting() {
        return creditWeighting;
    }

    public void setCreditWeighting(int creditWeighting) {
        this.creditWeighting = creditWeighting;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public char getStage() {
        return stage;
    }

    public void setStage(char stage) {
        this.stage = stage;
    }

    public String[] getPreReqModules() {
        String[] pr = new String[preReqModuleList.size()];
        int i = 0;
        while(i < pr.length){
            pr[i] = preReqModuleList.get(i);
            i++;
        }
        return pr;
    }

    public void addPreReqModule(String moduleCode) throws PreReqModuleAlreadyAssociatedWithModuleException{
        if(preReqModuleList.contains(moduleCode)){
            throw new PreReqModuleAlreadyAssociatedWithModuleException();
        } else {
            preReqModuleList.add(moduleCode);
        }
    }

    public void removePreReqModule(String moduleCode) throws PreReqModuleNotAssociatedWithModuleException{
        if(preReqModuleList.contains(moduleCode)){
            preReqModuleList.remove(moduleCode);
        } else {
            throw new PreReqModuleNotAssociatedWithModuleException();
        }
    }

    public void addStudent(String emailID) throws StudentAlreadyOnCourseException{
        if(preReqModuleList.contains(emailID)){
            throw new StudentAlreadyOnCourseException();
        } else {
            preReqModuleList.add(emailID);
        }
    }

    public void removeStudent(String emailID) throws StudentNotOnCourseException{
        if(preReqModuleList.contains(emailID)){
            preReqModuleList.remove(emailID);
        } else {
            throw new StudentNotOnCourseException();
        }
    }

    public String getCoordinatorID() {
        return coordinatorID;
    }

    public void setCoordinatorID(String coordinatorID) {
        this.coordinatorID = coordinatorID;
        //get coordinator associated with ID, add to their coordinator module list
    }

    public String[] getLecturers() {
        String[] le = new String[lecturers.size()];
        int i = 0;
        while(i < le.length){
            le[i] = lecturers.get(i);
            i++;
        }
        return le;
    }

    public void addLecturer(String emailID) throws LecturerAlreadyAssociatedWithModuleException{
        if(lecturers.contains(emailID)){
            throw new LecturerAlreadyAssociatedWithModuleException();
        } else {
            lecturers.add(emailID);
        }
        //get staff member and add module to their list
    }

    public void removeLecturer(String emailID) throws LecturerNotAssociatedWithModuleException{
        if(lecturers.contains(emailID)){
            lecturers.remove(emailID);
        } else {
            throw new LecturerNotAssociatedWithModuleException();
        }
        //get staff member and remove module from their list
    }






}
